#include<bits/stdc++.h>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status;
typedef struct LNode{
	int data;
	LNode *next;	
}LNode, *LinkList; 
Status Init(LinkList &L)
{
	L = new LNode;
	if(!L) return ERROR;
	L->next = NULL;
	return OK;
}
Status Create(LinkList &L, int n)
{
	LNode *t = L;
	for(int i = 0; i < n; i ++)
	{
		LNode *p = new LNode;
		if(!p) return ERROR;
		cin >> p->data;
		p->next = t->next;
		t->next = p;
		t = p;
	}
	return OK;
}
void Get_Common(LinkList A, LinkList B, LinkList &C)
{
	/********************Begin*********************/
	LNode *pa = A->next;
	LNode *pb = B;
	LNode *pc = C;
	while(pa)
	{
		pb = B->next;
		while(pb)
		{
			if(pa->data == pb->data)
			{
				LNode *q = new LNode;
				q->data = pa->data;
				q->next = NULL;
				pc->next = q;
				pc = q;
				break;
			}
			pb = pb->next;
		}
		pa = pa->next; 
	}
    /*********************End*******************/
}
void Show(LinkList L)
{
	LNode *p = L->next;
	while(p)
	{
		cout << p->data << ' ';
		p = p->next;
	}
	cout << endl;
}
int main()
{
	LinkList L1, L2, L3;
	Init(L1);
	Init(L2);
	Init(L3);
	
	int n1, n2;
	cin >> n1 >> n2;
	
	Create(L1, n1);
	Create(L2, n2);
	
	Get_Common(L1, L2, L3);
	 
	Show(L3);
	return 0;
}